package pers.qianyu.month_202012.date_20201211;

import org.junit.*;

/**
 * 518. 零钱兑换 II
 * https://leetcode-cn.com/problems/coin-change-2/
 *
 * @author mizzle rain
 * @date 2020-12-11 20:43
 */
public class ChangeTwo {
    /**
     * 一维数组解法
     */
    public int change(int amount, int[] coins) {
        int[] dp = new int[amount + 1];
        dp[0] = 1;
        for (int coin : coins) {
            for (int i = coin; i < dp.length; i++) {
                dp[i] += dp[i - coin];
            }
        }
        return dp[amount];
    }

    @Test
    public void test1() {
        int result = new ChangeTwo().change(5, new int[]{1, 2, 5});
        System.out.println("result = " + result);
    }
}
